package com.mumu.jetpackdemo.page;

import android.arch.paging.PagedListAdapter;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.recyclerview.extensions.AsyncDifferConfig;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.telecom.Call;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * edie create on 2019/3/29
 */
public class My2Adapter extends PagedListAdapter<String, My2Adapter.My2VH> {

    protected My2Adapter(@NonNull DiffUtil.ItemCallback<String> diffCallback) {
        super(diffCallback);
    }

    protected My2Adapter(@NonNull AsyncDifferConfig<String> config) {
        super(config);
    }

    public My2Adapter() {
        super(mDiffCallback);
    }

    private static DiffUtil.ItemCallback<String> mDiffCallback = new DiffUtil.ItemCallback<String>() {

        @Override
        public boolean areItemsTheSame(@NonNull String s, @NonNull String t1) {
            return s.equals(t1);
        }

        @Override
        public boolean areContentsTheSame(@NonNull String s, @NonNull String t1) {
            return s.equals(t1);
        }
    };

    @NonNull
    @Override
    public My2VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_2, null);

        return new My2VH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My2VH holder, int position) {
        String item = getItem(position);
        holder.text1.setText(String.valueOf(position));
        holder.text2.setText(item);
    }

    class My2VH extends RecyclerView.ViewHolder {
        public TextView text1;
        public TextView text2;

        public My2VH(@NonNull View itemView) {
            super(itemView);
            text1 = itemView.findViewById(android.R.id.text1);
            text1.setTextColor(Color.RED);

            text2 = itemView.findViewById(android.R.id.text2);
            text2.setTextColor(Color.BLUE);

        }
    }
}
